<template>
  <div class="ShopAccount">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }"
        ><i class="lh lh-diaodu fw_100"></i
      ></el-breadcrumb-item>
      <el-breadcrumb-item>消息推送</el-breadcrumb-item>
      <el-breadcrumb-item>发送记录查询</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="content_Box box-shadow abnormal mt_15">
      <div class="py_5 px_10">
        <el-row>
          <el-col :span="22">
            <el-form
              :inline="true"
              class="form-inline fr"
              @keyup.enter.native="shearchBtn()"
            >
              <!-- <el-form-item>
								<el-input v-model="query.name" placeholder="姓名"></el-input>
							</el-form-item> -->
              <el-form-item>
                <el-input
                  v-model="query.mobile"
                  placeholder="手机号"
                ></el-input>
              </el-form-item>
              <!-- <el-form-item>
								<el-select v-model="query.cate" placeholder="任务名称" clearable>
									<el-option :label="item.case_title" :value="item.id" v-for="(item, index) in pushList" :key="index">{{
										item.case_title
									}}</el-option>
								</el-select>
							</el-form-item> -->
              <el-form-item class="w_100">
                <el-select
                  v-model="query.status"
                  placeholder="推送状态"
                  clearable
                >
                  <!--									<el-option label="已创建" value="1"></el-option>-->
                  <!--									<el-option label="发送中" value="2"></el-option>-->
                  <el-option label="发送完成" value="3"></el-option>
                  <!--									<el-option label="已读取" value="4"></el-option>-->
                  <el-option label="发送失败" value="5"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item prop="start_time">
                <el-date-picker
                  class="w_180i"
                  v-model="query.start_time"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  format="yyyy-MM-dd HH:mm:ss"
                  default-time="00:00:00"
                  placeholder="发送开始时间"
                >
                </el-date-picker> </el-form-item
              >~
              <el-form-item prop="end_time">
                <el-date-picker
                  class="w_180i"
                  v-model="query.end_time"
                  type="datetime"
                  value-format="yyyy-MM-dd HH:mm:ss"
                  format="yyyy-MM-dd HH:mm:ss"
                  default-time="23:59:59"
                  placeholder="发送结束时间"
                >
                </el-date-picker>
              </el-form-item>
              <el-button
                size="mini"
                type="primary"
                class="round-right"
                native-type="button"
                @click="shearchBtn"
                >搜索</el-button
              >
              <el-button size="mini" round @click="resetDataBtn"
                >重置</el-button
              >
            </el-form>
          </el-col>
        </el-row>
      </div>
      <div class="tableMaxBox">
        <template>
          <!-- 表格部分 -->
          <el-table :data="demandList" stripe>
            <el-table-column prop="id" label="序号" width="50px" align="center">
              <template slot-scope="{ $index }">
                <span>{{ $index + 1 }}</span>
              </template>
            </el-table-column>
            <!-- <el-table-column prop="name" label="姓名" width="120px"> </el-table-column> -->
            <el-table-column prop="mobile" label="手机号" width="120px">
            </el-table-column>
            <el-table-column prop="title" label="任务名称" width="150px">
            </el-table-column>
            <el-table-column prop="info" label="消息标题" min-width="250px">
            </el-table-column>
            <el-table-column prop="status" label="发送状态" width="120px">
              <template slot-scope="{ row }">
                <span v-if="row.status == '1'">已创建</span>
                <span v-if="row.status == '2'">发送中</span>
                <span v-if="row.status == '3'">发送完成</span>
                <span v-if="row.status == '4'">已读取</span>
                <span v-if="row.status == '5'">发送失败</span>
                  <div style="color:#c00;">{{row.errmsg}}</div>
              </template>
            </el-table-column>
            <el-table-column
              prop="add_time"
              label="发送时间"
              width="150px"
            ></el-table-column>
            <el-table-column label="操作" min-width="50" fixed="right">
              <template slot-scope="{ row }">
                <el-link
                  :underline="false"
                  type="primary"
                  @click="showMore(row)"
                  >详情</el-link
                >
              </template>
            </el-table-column>
          </el-table>
          <!-- 分页组件 -->
          <page
            :total="total"
            :pageNums="pageNum"
            :disableMountedFetch="true"
            @pagedata="onChildValue"
          ></page>
        </template>
      </div>
    </div>
    <!-- 审核状态-弹框 -->
    <el-dialog
      title="发送详情"
      :visible.sync="auditState"
      width="620px"
      :close-on-click-modal="false"
    >
      <div class="auditCentent">
        <div class="row-info clear" style="margin-bottom: 10px">
          <div class="fl title-key">手机号：</div>
          <div class="fl list-cont">
            {{ ret.mobile }}
          </div>
        </div>
        <div class="row-info clear">
          <div class="fl title-key">消息标题：</div>
          <div class="fl list-cont">
            {{ ret.info }}
          </div>
        </div>
        <div class="row-info clear">
          <div class="fl title-key">任务名称：</div>
          <div class="fl list-cont">
            {{ ret.title }}
          </div>
        </div>
        <div class="row-info clear" v-if="ret.remark">
          <div class="fl title-key">备注：</div>
          <div class="fl list-cont">
            {{ ret.remark }}
          </div>
        </div>
        <div class="row-info clear">
          <div class="fl title-key">跳转页面：</div>
          <div class="fl list-cont">
            {{ ret.url }}
          </div>
        </div>
      </div>
      <div slot="footer" class="dialog-footer">
        <span class="resetBtn" @click="closeDialog()">关闭</span>
      </div>
    </el-dialog>
  </div>
</template>

<script>
var common = require('../../../static/tool.js')
import { sendList, fetchMessage } from '@/api/push.js'

export default {
  name: 'PushList',
  data() {
    return {
      manageInfo: JSON.parse(sessionStorage.getItem('manageInfo')), //登录信息
      url: common.url,
      head_url: common.head_url,
      //搜索对应值
      query: {
        mobile: '',
        // name: '',
        status: '',
        start_time: '',
        end_time: ''
      },
      demandList: [],
      //向分页组件传值
      total: 0,
      pageNum: 1,
      pageSizeNow: 20,
      auditState: false,
      ret: {}
    }
  },
  created() {
    if (this.$route.query.id) {
      this.cate = +this.$route.query.id
    }
    this.listData()
  },
  mounted() { },
  methods: {
    async listData() {
      try {
        let ret = await sendList({
          pageSize: this.pageSizeNow,
          page: this.pageNum,
          ...this.query,
          cate: this.cate
        })
        if (ret.list) {
            ret.list.forEach(it => {
                it.errmsg = ''
                if (it && it.msg && it.msg.msg) {
                    if (typeof it.msg.msg === 'string') {
                        it.errmsg = it.msg.msg
                    }
                    else if (it.msg.msg.errmsg) {
                        it.errmsg = it.msg.msg.errmsg === 'ok' ? '' : it.msg.msg.errmsg
                    }
                }
            })
          this.demandList = ret.list
          this.total = ret.count
        } else {
          this.demandList = []
          this.total = 0
        }
      } catch (err) {
        console.log('err:', err)
      }
    },
    shearchBtn() {
      this.pageNum = 1
      this.listData()
    },
    resetDataBtn() {
      this.resetData()
      this.listData()
    },
    resetData() {
      this.pageNum = 1
      this.query = {
        mobile: '',
        // name: '',
        // status: '',
        start_time: '',
        end_time: ''
      }
    },
    async showMore(row) {
      this.auditState = true
      this.ret = row
    },
    closeDialog() {
      this.auditState = false
      this.ret = {}
    },
    //分页组件->子组件传值
    onChildValue(item) {
      this.pageNum = item[0]
      this.pageSizeNow = item[1]
      this.listData()
    }
  }
}
</script>

<style scoped>
.top {
  display: flex;
  margin-bottom: 20px;
}
.box1 {
  margin-right: 30px;
}

.label-name {
  width: 100px;
  text-align: right;
  font-size: 12px;
  color: #888888;
  line-height: 34px;
  float: left;
}

.label-value {
  font-size: 14px;
  color: #353c48;
  line-height: 34px;
  padding-left: 10px;
  float: left;
}
.money {
  color: #d40505;
  margin-right: 20px;
}
.auditCentent_next {
  display: flex;
  margin-bottom: 10px;
}

.wrap-timeline {
  display: block;
  overflow: auto;
  margin-bottom: 20px;
}

.gys-style {
  font-size: 16px;
  text-align: center;
  background: #4fc5ca;
  padding: 10px 0;
  border-radius: 0px;
  color: #fff;
  position: relative;
  top: -30px;
  width: 500px;
  left: -20px;
}
</style>
<style>
.tableMaxBox .el-table th .el-checkbox__input {
  display: block;
}
</style>



// WEBPACK FOOTER //
// src/components/messagepush/FetchList.vue